package com.ankicoo.practice.daily;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Description: 3. 无重复字符的最长子串
 *
 * @author : QCYANG
 * @date : 2022/11/2 15:54
 */
public class LC3 {
    public static int lengthOfLongestSubstring(String s) {
        Map<Character,Integer> temp = new HashMap<>();
        int max = 0;
        int left = 0;
        for(int i = 0; i<s.length() ;i++){
            char cur = s.charAt(i);
            if (temp.containsKey(cur)) {
                left = Math.max(left,temp.get(cur) + 1);
            }
            temp.put(cur,i);
            max = Math.max(max, i-left+1);
        }
        return max;
    }

    public static void main(String[] args) {
        String  target = "abcbacbb";
        int max = lengthOfLongestSubstring(target);
        System.out.println(max);
    }
}
